<template>
	<view class="wapper">
		<u-navbar :autoBack="true" leftIconColor="#fff" height="90rpx" titleStyle="color:#fff" title="维修工单"
			:bgColor="bgColor">
		</u-navbar>
		<view class="clear"></view>
		<view class="con-con">
			<view class="con-title">
				{{detailInfo.workOrderStatusStr}}
			</view>
			<view class="content">
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-title">
							工单编号
						</view>

					</u-col>
					<u-col span="4">
						<view class="item-title">
							工单类型
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-title">
							维修类型
						</view>
					</u-col>

				</u-row>
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.workOrderNo}}
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.workOrderTypeStr}}
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.fixTypeStr}}
						</view>
					</u-col>

				</u-row>
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-title">
							船舶名称
						</view>

					</u-col>
					<u-col span="4">
						<view class="item-title">
							发起人
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-title">
							发起时间
						</view>
					</u-col>

				</u-row>
				<u-row justify="space-between">
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.boatName}}
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.createByName}}
						</view>
					</u-col>
					<u-col span="4">
						<view class="item-val">
							{{detailInfo.createTime}}
						</view>
					</u-col>

				</u-row>

				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-title">
							维修备注
						</view>

					</u-col>


				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-val">
							{{detailInfo.remark ||'-'}}
						</view>

					</u-col>


				</u-row>
			</view>
			<view class="pro-content">
				<view class="pro-title">
					维修项目
				</view>
				<view class="pro-header">
					<view class="head-index">
						序号
					</view>

					<view class="head-one">
						维修项目
					</view>
				</view>
				<template v-if="detailInfo.detailList && detailInfo.detailList.length>0">
					<view class="pro-list clearfix" v-for="(item,index) in detailInfo.detailList" :key="index">
						<view class="list-index">{{index+1}}</view>
						<view class="list-one">{{item.fixProjectName}}</view>

					</view>

				</template>
				<view class="clear"></view>
			</view>
			<view class="content " v-if="detailInfo.workOrderStatus===4  ">
				<view class="result-title">
					维修结果
				</view>
				<view class="content-grey">
					<template v-if="detailInfo.fixType===1">
						<u-row justify="space-between">
							<u-col span="12">
								<view class="item-title">
									实际维修人
								</view>

							</u-col>


						</u-row>
						<u-row justify="space-between">
							<u-col span="12">
								<view class="item-val">
									{{detailInfo.fixByName}}
								</view>

							</u-col>


						</u-row>
					</template>

					<template v-if="detailInfo.fixType===2">
						<u-row justify="space-between">
							<u-col span="12">
								<view class="item-title">
									维修厂家
								</view>

							</u-col>


						</u-row>
						<u-row justify="space-between">
							<u-col span="12">
								<view class="item-val">
									{{detailInfo.factoryName}}
								</view>

							</u-col>


						</u-row>
					</template>

					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-title">
								实际维修时间
							</view>

						</u-col>


					</u-row>
					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-val">
								{{detailInfo.actualStartTime}} ~ {{detailInfo.actualEndTime}}
							</view>

						</u-col>


					</u-row>
					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-title">
								维修情况
							</view>

						</u-col>


					</u-row>
					<u-row justify="space-between">
						<u-col span="12">
							<view class="item-val">
								{{detailInfo.fixResult}}
							</view>

						</u-col>


					</u-row>

				</view>
			</view>

			<view class="money-content" >
				<view class="money-title">
					<view class="title-name">维修费用</view>
					<view class="money">总费用 <text v-if="detailInfo.fixFeeAmount">
							{{detailInfo.fixFeeAmount.toFixed(2)}}
						</text>
						<text v-else>0</text>
						元
					</view>

				</view>
				<template v-if="detailInfo.fixType===2  && detailInfo.workOrderStatus===4">
					<view class="small-title">维修厂家及费用</view>
					<view class="factory-header">
						<view class="head-index">
							序号
						</view>
						<view class="head-one">
							维修厂家
						</view>
						<view class="head-two">
							维修费用
						</view>
					</view>
					<template
						v-if="detailInfo.fixWorkOrderFactoryDtoList && detailInfo.fixWorkOrderFactoryDtoList.length>0">
						<view class="factory-list clearfix" v-for="(item,index) in detailInfo.fixWorkOrderFactoryDtoList"
							:key="index">
							<view class="list-index">{{index+1}}</view>
							<view class="list-one">{{item.factoryName}}</view>
							<view class="list-two">
								<template v-if="item.fixFeeAmount">
									{{item.fixFeeAmount.toFixed(2)}}
								</template>
								<template v-else>0</template>
								元
							</view>
						</view>
					
					</template>
					<view class="clear"></view>
				</template>
				

				<view class="small-title">维修项目及费用</view>
				<view class="money-header">
					<view class="head-index">
						序号
					</view>
					<view class="head-one">
						维修项目
					</view>
					<view class="head-two">
						维修费用
					</view>
				</view>
				<template v-if="detailInfo.practicalDetailList && detailInfo.practicalDetailList.length>0">
					<view class="money-list clearfix" v-for="(item,index) in detailInfo.practicalDetailList" :key="index">
						<view class="list-index">{{index+1}}</view>
						<view class="list-one">{{item.fixProjectName}}</view>
						<view class="list-two">
							<template v-if="item.fixFeeAmount">
								{{item.fixFeeAmount.toFixed(2)}}
							</template>
							<template v-else>0</template>
							元
						</view>
					</view>

				</template>
				<view class="clear"></view>
			</view>
			<view class="content" v-if="detailInfo.workOrderStatus===5">
				<view class="result-title">
					审批结果
				</view>

				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-title">
							审批结果
						</view>

					</u-col>
				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-val">
							{{detailInfo.workOrderStatusStr}}
						</view>

					</u-col>
				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-title">
							驳回原因
						</view>

					</u-col>
				</u-row>
				<u-row justify="space-between">
					<u-col span="12">
						<view class="item-val">
							{{detailInfo.rejectReason}}
						</view>

					</u-col>


				</u-row>
			</view>
			<stepsList :approvalRecordDtoList="detailInfo.approvalRecordDtoList"
				v-if="detailInfo.approvalRecordDtoList && detailInfo.approvalRecordDtoList.length>0"></stepsList>

		</view>

		<view class="submit-btn" @click="handleSubmitShow()" v-if="detailInfo.chooseLeaderFlag===1">
			<text>提报分管领导审批</text>
			<u-icon name="play-right-fill" color="#407FFF" size="10"></u-icon>
		</view>
		<!-- 填写维修结果 -->
		<view class="footer" @click="navTo('/subMaintenance/repair/submitResult?id='+id+'&fixType='+detailInfo.fixType)"
			v-if="detailInfo.workOrderStatus===2    && detailInfo.hasAuth===1">
			填写维修结果
		</view>
		<!-- 审批结果 -->
		<Approval v-if="(detailInfo.workOrderStatus===1 || detailInfo.workOrderStatus===3 )  && detailInfo.hasAuth===1"
			:id="id" type="2" @getDetail="getDetail"></Approval>

		<u-modal :show="showConfirm" @cancel="showConfirm=false" @confirm="handleSubmit()" :showCancelButton="true"
			title="提示" content='是否确认提交?'></u-modal>
	</view>
</template>

<script>
	import {
		getWorkOrderDetail,
		approveWorkOrderRepair
	} from '@/api/repair.js'
	import stepsList from '@/components/steps/stepsList'
	import Approval from '@/components/approval/index'
	import Check from '@/components/check/index'
	export default {
		components: {
			stepsList,
			Approval,
			Check
		},
		filters: {

		},
		data() {
			return {
				bgColor: '#F1C060',
				id: null,
				detailInfo: {},
				showConfirm: false

			}
		},
		onLoad(option) {
			this.id = option.id || ''

		},
		onShow() {
			this.getDetail()
		},
		created() {

		},

		methods: {
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			getDetail() {
				this.detailInfo = {}
				const id = this.id
				getWorkOrderDetail({
					id
				}).then(response => {
					this.detailInfo = response.data

					if (this.detailInfo.approvalUserList && this.detailInfo.approvalUserList.length > 0) {
						let approvalUserList = []
						for (let i = 0; i < this.detailInfo.approvalUserList.length; i++) {
							approvalUserList.push(this.detailInfo.approvalUserList[i].userName)
						}
						this.approvalUserList = approvalUserList.toString()

					}
					// const endData = {
					// 	planTime: [response.data.planStartTime, response.data.planEndTime],
					// 	...response.data
					// }
					// this.editForm = endData
					// if (this.editForm.projectInfoList && this.editForm.projectInfoList.length > 0) {
					// 	let newArr = []
					// 	for (let i = 0; i < this.editForm.projectInfoList.length; i++) {
					// 		newArr.push(this.editForm.projectInfoList[i].projectId)
					// 	}
					// 	this.editForm.projectIdList = [...newArr]

					// } else {
					// 	this.editForm.projectInfoList = []
					// }


				})
			},
			handleSubmitShow() {
				this.showConfirm = true
			},
			handleSubmit() {
				const paramData = {
					id: this.id,
					approvalResult: 1,
					centerLeaderApproval: 1
				}
				this.showConfirm = false
				uni.showLoading({
					mask: true,
					title: '提交中'
				})
				approveWorkOrderRepair(paramData).then(response => {
					if (response.code === 200) {
						uni.showToast({
							icon: 'none',
							title: '提交成功',
							mask: true,
							duration: 2000,
						})
						this.getDetail()
						uni.hideLoading()

					} else {
						uni.hideLoading()
					}

				})

			},

		}
	}
</script>

<style lang="scss" scoped>
	.wapper {
		width: 100vw;
		min-height: 100vh;
		background: #F5F7F9 url('@/static/image/detail/repair_bg.png') no-repeat top center;
		background-size: 100% auto;
		padding-bottom: 70rpx;

		.clear {
			clear: both;
		}


		.con-con {
			margin: 0 26rpx;
			padding-top: 126rpx;

			.con-title {
				font-size: 50rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #FFFFFF;
				line-height: 70rpx;
				margin-bottom: 20rpx;
				padding-top: 54rpx;
			}

			.content-grey {
				background: #F5F7F9 !important;
				border-radius: 16rpx;
				margin: 0 auto;
				padding: 34rpx 14rpx 24rpx 14rpx;
			}

			.content {
				background: #FFFFFF;
				border-radius: 16rpx;
				padding: 30rpx 18rpx;
				box-sizing: border-box;
				margin-bottom: 10rpx;

				.result-title {
					font-size: 28rpx;
					font-weight: 500;
					color: #323232;
					margin-bottom: 25rpx;
				}

				.item-title {
					font-size: 22rpx;
					font-weight: 400;
					color: #909399;
					margin-bottom: 10rpx;
				}

				.item-val {
					font-size: 27rpx;
					font-weight: 500;
					color: #323232;
					margin-bottom: 40rpx;
				}

			}

			.pro-content {
				background: #FFFFFF;
				border-radius: 16rpx;
				padding: 30rpx 18rpx;
				box-sizing: border-box;
				margin-bottom: 10rpx;

				.pro-title {
					font-size: 28rpx;
					font-weight: 500;
					color: #323232;
					margin-bottom: 25rpx;
				}

				.pro-header {
					background: #F5F7FA;
					border-radius: 3rpx;
					height: 60rpx;
					line-height: 60rpx;
					font-size: 22rpx;
					font-weight: 400;
					color: #8C99A7;

					.head-index {
						width: 110rpx;
						text-align: center;
						float: left;
					}

					.head-one {
						width: calc(100% - 110rpx);
						float: left;
					}


				}

				.pro-list {
					padding: 10rpx 0;
					font-size: 22rpx;
					font-weight: 400;
					color: #303133;
					line-height: 36rpx;
					min-height: 40rpx;

					.list-index {
						width: 110rpx;
						text-align: center;
						float: left;
					}

					.list-one {
						width: calc(100% - 110rpx);
						float: left;
					}

					&:nth-child(2n) {
						background: #F5F7FA;
					}

					&::after {
						clear: both;
					}
				}
			}

			.money-content {
				background: #FFFFFF;
				border-radius: 16rpx;
				padding: 30rpx 18rpx;
				box-sizing: border-box;
				margin-bottom: 10rpx;

				.small-title {
					height: 30rpx;
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #909399;
					margin: 18rpx auto;
				}

				.money-title {
					margin-bottom: 25rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.title-name {
						font-size: 28rpx;
						font-weight: 500;
						color: #323232;
					}

					.money {
						font-size: 28rpx;
						font-weight: 400;
						color: #323232;
						margin: 0 10rpx;
					}

				}

				.factory-header {
					background: #F5F7FA;
					border-radius: 3rpx;
					height: 60rpx;
					line-height: 60rpx;
					font-size: 22rpx;
					font-weight: 400;
					color: #8C99A7;

					.head-index {
						width: 110rpx;
						text-align: center;
						float: left;
					}

					.head-one {
						width: calc(100% - 310rpx);
						float: left;
					}

					.head-two {
						float: left;
						width: 100rpx;
					}
				}

				.factory-list {
					padding: 10rpx 0;
					font-size: 22rpx;
					font-weight: 400;
					color: #303133;

					.list-index {
						width: 110rpx;
						text-align: center;
						float: left;
					}

					.list-one {
						width: calc(100% - 300rpx);
						float: left;
					}

					.list-two {
						float: left;
						width: 100rpx;
					}

					&:nth-child(2n+1) {
						background: #F5F7FA;
					}

					&::after {
						clear: both;
					}
				}

				.money-header {
					background: #F5F7FA;
					border-radius: 3rpx;
					height: 60rpx;
					line-height: 60rpx;
					font-size: 22rpx;
					font-weight: 400;
					color: #8C99A7;

					.head-index {
						width: 110rpx;
						text-align: center;
						float: left;
					}

					.head-one {
						width: 284rpx;
						float: left;
					}

					.head-two {
						float: left;
						width: calc(100% - 394rpx);
					}
				}

				.money-list {
					padding: 10rpx 0;
					font-size: 22rpx;
					font-weight: 400;
					color: #303133;

					.list-index {
						width: 110rpx;
						text-align: center;
						float: left;
					}

					.list-one {
						width: 284rpx;
						float: left;
					}

					.list-two {
						float: left;
						width: calc(100% - 394rpx);
						// width: 266rpx;
					}

					&:nth-child(2n+1) {
						background: #F5F7FA;
					}

					&::after {
						clear: both;
					}
				}
			}

		}

		.submit-btn {
			width: 690rpx;
			height: 104rpx;
			border: 2rpx solid #407FFF;
			border-radius: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 36rpx;
			font-weight: 400;
			color: #407FFF;
			margin: 70rpx auto 0 auto;

			text {
				margin-right: 10rpx;
			}
		}

		.footer {
			width: 690rpx;
			height: 104rpx;
			background: #407FFF;
			border-radius: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 36rpx;
			font-weight: 400;
			color: #FFFFFF;
			margin: 70rpx auto 0 auto;
		}
	}
</style>
